/**
 * 各种画echarts图表的方法都封装在这里
 * 注意：这里echarts没有采用按需引入的方式，只是为了方便学习
 */

import echarts from 'echarts'
import json from '../data/chart.json'
console.log(json)
const install = function(Vue) {
    Object.defineProperties(Vue.prototype, {
        $chart: {
            get() {
                return {
                    //画一条简单的线
                    line1: function (id) {
                        this.chart = echarts.init(document.getElementById(id));
                        this.chart.clear();
                        const optionData = {
                            xAxis: {
                                type: 'category',
                                data: json.x
                            },
                            yAxis: {
                                type: 'value'
                            },
                            dataZoom: [{
                                type: 'inside',
                                xAxisIndex: [0],
                                start: 0,
                                end: 15
                            }, ],
                            grid:{
                                x:40,
                                y:40,
                                x2:15,
                                y2:20,
                                borderWidth:1
                            },
 
                            series: [{
                                data: json.y,
                                type: 'line',
                                smooth: true
                            }]
                        };

                        this.chart.setOption(optionData);
                    },
                }
            }
        }
    })
}

export default {
    install
}
